package com.ezops.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ezops.models.Menu;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

@Controller
@RequestMapping("/menu")
public class MenuController {
	/**
	 * To get list of menu and sub-menu of portal
	 * 
	 * @return
	 * @throws JsonProcessingException
	 */
	@RequestMapping(value = "/getportalmenuwithsubmenu", method = RequestMethod.GET, produces = "application/json")
	public @ResponseBody
	String getPortalMenuWithSubMenu() throws JsonProcessingException {
		String menuJson = getJSonData();
		return menuJson;
	}

	private String getJSonData() throws JsonProcessingException {

		ObjectMapper mapper = new ObjectMapper();
		String json = "";

		HashMap<String, Object> navMap = new HashMap<String, Object>();
		List<Menu> menuList = new ArrayList<Menu>();

		Menu menu = new Menu();
		menu.setResourceName("Dashboard");
		menu.setResourceUrl("/dashboard");
		menu.setEntypoIconClass("entypo-gauge");
		menuList.add(menu);

		Menu menu1 = new Menu();
		menu1.setResourceName("Trade Monitor");
		menu1.setResourceUrl("/trademonitor");
		menu1.setEntypoIconClass("entypo-gauge");
		List<Menu> menuItemsList = new ArrayList<Menu>();
		Menu menu1Sub = new Menu();
		menu1Sub.setResourceName("Exception Report");
		menu1Sub.setResourceUrl("/exceptionReport");
		menu1Sub.setEntypoIconClass("entypo-chart-pie");
		menuItemsList.add(menu1Sub);
		menu1.setMenuItems(menuItemsList);
		menuList.add(menu1);

		Menu menu2 = new Menu();
		menu.setResourceName("Field Mapping");
		menu.setResourceUrl("/fieldMapping");
		menu.setEntypoIconClass("entypo-gauge");
		menuList.add(menu2);

		navMap.put("navMap", menuList);
		json = mapper.writeValueAsString(navMap);

		System.out.println(json);

		return json;
	}

	/*
	 * public static void main(String[] args) throws JsonProcessingException {
	 * ObjectMapper mapper = new ObjectMapper(); String json = "";
	 * 
	 * HashMap<String, Object> navMap = new HashMap<String, Object>();
	 * List<Menu> menuList = new ArrayList<Menu>();
	 * 
	 * Menu menu = new Menu(); menu.setResourceName("Dashboard");
	 * menu.setResourceUrl("/dashboard");
	 * menu.setEntypoIconClass("entypo-gauge"); menuList.add(menu);
	 * 
	 * Menu menu1 = new Menu(); menu1.setResourceName("Reports"); List<Menu>
	 * menuItemsList = new ArrayList<Menu>(); Menu menu1Sub = new Menu();
	 * menu1Sub.setResourceName("Trade Processing");
	 * menu1Sub.setResourceUrl("/tradeProcessing");
	 * menu1Sub.setEntypoIconClass("entypo-gauge"); menuItemsList.add(menu1Sub);
	 * menu1.setMenuItems(menuItemsList); menuList.add(menu1);
	 * 
	 * Menu menu2 = new Menu(); menu.setResourceName("Operations Dashboard");
	 * menu.setResourceUrl("/operationsDashboard");
	 * menu.setEntypoIconClass("entypo-gauge"); menuList.add(menu2);
	 * 
	 * navMap.put("navMap", menuList); json = mapper.writeValueAsString(navMap);
	 * 
	 * System.out.println(json); }
	 */
}
